
class Solution {
public:
    int findMin(vector<int>& nums) {
        int len=nums.size();
        int left=0;
        int right=len-1;
        int mid=0;
        while(left<right){
            mid=(left+right)/2;
            if(mid>0&&nums[mid]<nums[mid-1]){
                return nums[mid];
            }
            if(nums[left]>nums[right]){
                if(nums[mid]<nums[left]){
                    right=mid-1;
                } else{
                    left=mid+1;
                }
            } else{
                cout<<"left:"<<left<<",mid:"<<mid<<",right:"<<right<<endl;
                break;
            }
            cout<<"left:"<<left<<",mid:"<<mid<<",right:"<<right<<endl;
        }
        return nums[left];
    }
};

/*
6 7 0 1 2 3 4

4 5 6 7 0 1 2

5 1 2 3 4

2 3 4 5 1

1 2 3 4 5

1 2 3

1 2

1
*/

class Solution {
public:
    int findMin(vector<int>& nums) {
        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = (r - l) / 2 + l;
            if (nums[mid] < nums[r]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return nums[l];
    }
};